﻿#pragma once


//-------------------------------
// QPen class
//-------------------------------
namespace micro{
namespace gui{



class QPen
{
	HPEN m_hPen;	
public:
	
	QPen(HPEN hPen=nullptr)	{ m_hPen=hPen;}
	
	QPen(int fnPenStyle/*=PS_SOLID*/,int nWidth=1,COLORREF clColor = 0 )
	{
		m_hPen=::CreatePen(fnPenStyle,nWidth,clColor);
	}

	~QPen()
	{
		DeleteObject();
	}

	inline operator HPEN(){return m_hPen;}

	BOOL IsValidPen() {return  (m_hPen!=nullptr); }
	
	HPEN GetPen() { if (! IsValidPen()) return nullptr; return m_hPen;}
	
	HPEN CreatePen(int fnPenStyle=PS_SOLID,int nWidth=1,COLORREF clColor=RGB(0,0,0))
	{
		if (IsValidPen()) return nullptr;
		m_hPen=::CreatePen(fnPenStyle,nWidth,clColor);
		return m_hPen;
	}

	HPEN ExtCreatePen( LOGBRUSH* lplb, int fnPenStyle=PS_SOLID,int nWidth=1, int dwStyleCount=0,  DWORD* lpStyle=nullptr )
	{
		if (IsValidPen()) return nullptr;
		m_hPen=::ExtCreatePen(fnPenStyle,nWidth,lplb,dwStyleCount,lpStyle);
		return m_hPen;
	}


	HPEN CreatePenIndirect( LOGPEN* lplgpen)
	{
		if (IsValidPen()) return nullptr;
		m_hPen=::CreatePenIndirect(lplgpen);
		return m_hPen;
	}

	void DeleteObject()
	{
		if (m_hPen)  
			::DeleteObject((HPEN)m_hPen);
		m_hPen = nullptr;
		
	}


	BOOL GetLogPen(LOGPEN* pLogPen) 
	{
		if (!IsValidPen()) return FALSE;
		return ::GetObject(m_hPen, sizeof(LOGPEN), pLogPen);
	}

	BOOL GetExtLogPen(EXTLOGPEN* pLogPen) 
	{
		if (!IsValidPen()) return FALSE;
		return ::GetObject(m_hPen, sizeof(EXTLOGPEN), pLogPen);
	}


};



}}//micro